package com.xgame.server.dbtool;

import com.xgame.server.netty.enity.MsgEntity;
import com.xgame.server.netty.proto.Cmdcode;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

@Component
public class GameUtilTool {

    public MsgEntity getCommonResult(Channel chanel, Integer code, Integer time, Integer revert, Integer result, Integer errcode) {
        MsgEntity resRt = new MsgEntity();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        resRt.setCmdCode(code);
        resRt.setChannel(chanel);
        resRt.setTimeStamp(time);
        resRt.setReserved(revert);
        Cmdcode.CommonResCS.Builder cc = Cmdcode.CommonResCS.newBuilder();
        cc.setResult(result);
        cc.setErrcode(errcode);
        cc.setTime(df.format(System.currentTimeMillis()));
        byte[] arrys = cc.build().toByteArray();
        resRt.setData(arrys);
        resRt.setMsgLength(arrys.length);

        return resRt;
    }

    public MsgEntity getReferResult(Channel chanel, Cmdcode.SaveCmdCode code, Integer time, Integer revert, byte[] data) {
        MsgEntity resRt = new MsgEntity();
        resRt.setCmdCode(code.getNumber());
        resRt.setChannel(chanel);
        resRt.setTimeStamp(time);
        resRt.setReserved(revert);
        resRt.setData(data);
        resRt.setMsgLength(data.length);

        return resRt;
    }
}
